const fs = require('fs')
const path = require('path')
// const utils = require('util')

const REMOVE_SUFFIX = 'REMOVE_SUFFIX'
const REMOVE_PREFIX = 'REMOVE_PREFIX'

const results = {}
function read(p) {
  try {
    const files = fs.readdirSync(p)
    for (const file of files) {
      const stats = fs.statSync(path.join(p, file))
      if (stats.isDirectory()) {
        read(path.join(p, file))
      } else {
        debugger
        results[p.slice(13) + '/index'] = `${REMOVE_PREFIX}() => import('@${p.slice(3)}/${file}')${REMOVE_SUFFIX}`
      }
    }
  } catch (err) {
    console.error(err)
  }
}
console.log(path.join('src', 'business','views'));
read(path.join('src', 'business','views'))
const js =
  'export default ' +
  JSON.stringify(results)
    .replace(/"REMOVE_PREFIX/g, '')
    .replace(/REMOVE_SUFFIX"/g, '').replace(/\\\\/g, '/')
fs.writeFile(path.join('src', 'router', 'business.js'), js, err => {
  if (err) console.error(err)
})
